home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: news.sprintlink.net!mv!usenet
- From: ENGR@GSSI.MV.COM (Michael Furman)
- Subject: Re: how slow are virtual functions?
- Message-ID: <DnLFGx.Bxr@mv.mv.com>
- Mime-Version: 1.0
- Organization: GSSI
- Date: Fri, 1 Mar 1996 14:41:20 GMT
- References: <4gioqc$9f0@onlink3.onlink.net> <31344ACF.1ABB@bbn.hp.com>
- X-Newsreader: WinVN 0.93.10
- X-Nntp-Posting-Host: gssi.mv.com
-
- In article <31344ACF.1ABB@bbn.hp.com>, Manfred_Lange@bbn.hp.com says...
- >
- >wfss16@onlink.net wrote:
- > ..... snip
- >You will have a runtime overhead, that is caused by the fact the address of
- a vi
- >rtual
- >function is determined during runtime. Each class has a address table
- (vtable) w
- >hich
- >also contains the address of all virtual functions declared and defined for
- that
- >
- >class. The runtime system has to look up the correct address depending on
- the ty
- >pe of
- >the object (the class the object is an instance of) and then calls the
- function.
- > This
- >mechanism is also known as late binding.
- >For non-virtual functions, the binding can be done during link-time. This
- means
- >that
- >no additional code has to be executed by the runtime-environment to
- determine th
- >e
- >address of the function to be executed.
- >So you will have a runtime overhead. But keep in mind, that the percentage
- of th
- >e
- >overhead in general is very small, as the code of the virtual function needs
- mor
- >e time
- >to execute than the code for the overhead in most cases. Also the
- address-lookup
- > is
- >implemented using hash-functions in most cases.
-
- Not correct. Overhead of "virtuality" is even less, because there is no need
- for hash-functions: offset in virtual table is known at the compilation
- time. In most cases (at list for compilers I know about) virtual function
- call is longe then regular by 2 - 3 CPU instruction (just extra
- dereferencing). It may be a littli bit more in case of multiple onheritance.
- --
- <<< If you received it by E-mail: it is a copy of post to the newsgroup >>>
- ---------------------------------------------------------------
- Michael Furman, (603)893-1109
- Geophysical Survey Systems, Inc. fax:(603)889-3984
- 13 Klein Drive - P.O. Box 97 engr@gssi.mv.com
- North Salem, NH 03073-0097 71543.1334@compuserve.com
- ---------------------------------------------------------------
-
-